/**
 * @file    main.cpp
 * @author  Zhao Jingting <2373893752@qq.com>
 * @date    Sun Oct 7 20:20:40 2021
 *
 * @brief   A test program for class Matrix.
 *
 */


/**
 * Set the specific typename.
 *
 * NOT THAT manual changes of random distribution
 * template is required when TN is changed.
 */


#include <iostream>
#include<cstdlib>
#include<random>
#include<chrono>
#include<ctime>
using namespace std;
#include "Matrix.h"




int main(int argc, char *argv[])
{
  
  /**
   * Setup the random generator.
   *
   * NOTE THAT when TN is changed, uniform_int_distribution.
   * needed to be changed accordingly.
   */

  srand(time(0));

  ///Creat an array to store the parameters entered by the user for later use.
  int input[6];
  for(int n=0;n<6;n++)
    {
      input[n]=atoi(argv[n+1]);

    }
  



  ///开辟新的动态数组用以储存矩阵内的数，大小由用户传入的参数定义
  double* elements_temp=new double[input[0]*input[1]*10];
  for(int n=0;n<input[0]*input[1];n++)
    {
      elements_temp[n]=rand()%10;
    
    }
  ///声明矩阵M1
  matrix<double>M1(input[0],input[1],elements_temp);
    cout<<"M1= "<<endl<<M1;

  double* elements_temp2=new double(input[2]*input[3]);
  for(int n=0;n<input[2]*input[3];n++)
    {
      elements_temp2[n]=rand()%10;
    }
  ///声明矩阵M2
  matrix<double>M2(input[2],input[3],elements_temp);
  cout<<"M2="<<endl<<M2;
  ///判断矩阵是否为方阵
  if(M2.is_square())
    {
      cout<<"M2 is square"<<endl;
    }
  else
    {
      cout<<"M2 is not square"<<endl;
    }
  delete[] elements_temp2;
  
  delete[] elements_temp;

   elements_temp=new double(input[4]);
  ///验证矩阵乘法
  
  for(int n=0;n<input[4];n++)
    {
      elements_temp[n]=rand()%10;
    }
  
  RowVector<double>R(input[4],elements_temp);
  cout<<"The RowVector is:"<<endl;
  cout<<R<<endl;
   delete[] elements_temp;
 
   elements_temp=new double(input[5]);
  for(int n=0;n<input[5];n++)
    {
      elements_temp[n]=rand()%10;
    }
  ColVector<double>C(input[5],elements_temp);
  delete[] elements_temp;

  cout<<"The ColVector is:"<<endl;
  cout<<C<<endl;
  cout<<"R*C equals:"<<R*C<<endl<<endl<<endl;
  
  cout<<C*R;
  cout<<"C*R equals:"<<endl;
  cout<<R*R<<C*C;
  ///执行delete操作防止内存泄漏。
  delete R.matrix_elements;
  delete C.matrix_elements;
 

  return 0;
  
}
